package services;

import domain.entities.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: Guillermo
 * Date: 22/08/12
 * Time: 15:30
 * To change this template use File | Settings | File Templates.
 */
@Service
public class VendorTypeService {

    private VendorTypeDAO vendorTypeDAO;

    public VendorTypeService() {
    }

    @Autowired
    public VendorTypeService(VendorTypeDAO vendorTypeDAO) {
        this.vendorTypeDAO = vendorTypeDAO;
    }

    public List<VendorType> findAll(){
        List<VendorType> types = vendorTypeDAO.findAll();
        Collections.sort(types);
        return types;
    }

    public VendorType findbyId(Integer id){
        return vendorTypeDAO.findById(id);
    }
    public VendorType findByDescripcion(String descripcion){
        return vendorTypeDAO.findByDescripcion(descripcion);
    }


    public void checkType(String descripcion){
        if (!descripcion.equals("") && !vendorTypeDAO.existByDescripcion(descripcion)){
            vendorTypeDAO.attachDirty(new VendorType(descripcion));
        }
        return ;
    }
}
